<template>
    <div>
        <div>
            <mt-header title="还款累计">
                <router-link to="/" slot="left">
                    <mt-button icon="back">返回</mt-button>
                </router-link>
                <mt-button icon="more" slot="right"></mt-button>
            </mt-header>
        </div>
        <van-pull-refresh v-model="isLoading" @refresh="onRefresh" style="height: 900px">
            <el-card style="border-radius: 14px; margin-top: 10px; width: 360px; margin-left: 6px" class="box-card">
                <div slot="header" class="clearfix">
                    <van-tag style="height: 24px; width: 76px" color="#7232dd">您的贷款累计</van-tag>
                    <el-button @click="$router.push('/repay')" style="float: right; padding: 3px 0" type="text">立即还款</el-button>
                </div>
                <van-tag style="height: 20px" type="primary">总贷款金额</van-tag> {{alreadyCreditTotalMoney}} 元
                <van-tag style="height: 20px; margin-left: 10px" type="success">总还款金额</van-tag> {{alreadyRepayTotalMoney}} 元
                <van-tag style="margin-top: 20px" color="#7232dd" plain>信用指数</van-tag><br/>
                <van-rate
                        style="margin-top: 10px"
                        v-model="rate"
                        :size="25"
                        color="#ffd21e"
                        void-icon="star"
                        void-color="#eee"
                />
            </el-card>
        </van-pull-refresh>
    </div>
</template>

<script>
    import Toast from "vant/lib/toast";
    import axios from "axios";

    export default {
        name: "count",
        data() {
            return {
                rate: 2,
                alreadyCreditTotalMoney: 0,
                alreadyRepayTotalMoney: 0,
                isLoading: false,
            }
        },
        created() {
            this.InitRepayCountList()
        },
        methods: {
            InitRepayCountList() {
                axios.get('http://124.70.180.155:8080/system/user/profile',
                    {
                        headers: { Authorization: sessionStorage.getItem('token')}
                    }).then(res => {
                    this.user = res.data.data
                    axios.get('http://124.70.180.155:8080/repay/data/selectPayOrderListBySysUser/' + this.user.userName,
                        {
                            headers: { Authorization: sessionStorage.getItem('token')}
                        }).then(res => {
                        console.log(res)
                        console.log('已贷款的总金额为' + res.data.creditMoney)
                        console.log('已还款的总金额为' + res.data.totalMoney)
                        this.alreadyCreditTotalMoney = res.data.creditMoney
                        this.alreadyRepayTotalMoney = res.data.totalMoney
                    })

                })

            },
            onRefresh() {
                setTimeout(() => {
                    Toast('刷新成功');
                    this.isLoading = false;
                    this.count++;
                }, 1000);
            },
        }
    }
</script>

<style scoped>

</style>
